<?php
/*
package com.attilax.fdb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.attilax.coll.ListX;
import com.attilax.io.dirx;
import com.attilax.io.pathx;
import com.attilax.lang.MapX;
import com.attilax.lang.YamlAtiX;
import com.attilax.lang.text.strUtil;
*/
require_once(dirname(__FILE__).'/../dsl/dslx.php');
require_once(dirname(__FILE__).'/../util/Map.php');
require_once(dirname(__FILE__).'/../util/ListX.php');
require_once(dirname(__FILE__).'/../io/dirx.php');
require_once(dirname(__FILE__).'/../io/File.php');
require_once(dirname(__FILE__).'/../str/strUtil.php');
require_once(dirname(__FILE__).'/../pronunciation/pronas.php');
  class FdbX {

 
//PHP閺傝纭舵稊鐔峰隘閸掑敀rivate public缁涘绱濇稉锟介懜顒佸灉娴狀兛绗夐悧瑙勫壈鐎规碍鍓版妯款吇娑撶皢ublic
	  public $ssql="";
	  public $table;
	
	public Function   exe($ssql)
	{
		$op=$ssql->get("op");
		if($op==("select"))
		{
		$li=	$this->executeQuery($ssql);
		
			return   $li;
		}
		
		if($op==("update") ||$op==("insert")||$op==("delete"))
		{
			return executeUpdate($ssql);
		}
		return $ssql;
		
	}

	private Function executeUpdate($ssql) {
		// TODO Auto-generated method stub
		return null;
	}
	public $colsGener;
	private   $whereExprs;
	private Function executeQuery($ssql) {
		$this->ssql=$ssql;
		$this->table=$ssql->get("table");
		$this->colsGener=  $ssql->get("cols");
		
		$this->whereExprs = $ssql->get("where");
		if( is_array($this->whereExprs ))
		{
			$this->whereExprs=new Map($this->whereExprs);
		}
		
		$partitions = ListX::newList();
		if ($this->whereExprs && $this->whereExprs->containsKey("cate")) {
					$cate_id = strUtil::toStr($this->whereExprs->get("cate"));
					$PatitionFolderName =$cate_id;
					 
					$partitions->add($PatitionFolderName);
					 
		}else if($this->whereExprs)
		{
			$type=	$this->whereExprs->get("type");
		 	if( $type=="LikeExpression")
		 	{
		 		return $this->ProcessLikeExpression();
		 	
		 	 
			} 
		}
		else
			$partitions =$this->listPatition();
		
		$GLOBALS["partitions"]=$partitions;
	//	print_r($GLOBALS);
	//	die();

		$li=new ArrayList();
		 $partitions= $partitions->toArray();
		 $GLOBALS["partitions_phparr"]=$partitions;
		foreach  ( $partitions as $part ) {
			$list_t=$this->list_by_partition($part);
			 $GLOBALS["list_tPa5".$part]=$list_t;
			
			$li->addAll($list_t);
			
			
		}
		 $GLOBALS["list_paa8"]=$li;
		// print_r($GLOBALS);die();
		return $li;
	}
	
	
	function ProcessLikeExpression()
	{
		$col=$this->whereExprs->get("propertyName")	;
		$exp=getFunExprs($col);
		$fun=$exp[0];
		$col_name=$exp[1];
		
		$partitions =$this->listPatition();
		$li=new ArrayList();
		$partitions= $partitions->toArray();
		$GLOBALS["partitions_phparr"]=$partitions;
		foreach  ( $partitions as $part ) {
			$list_t=$this->list_by_partition($part);
			$GLOBALS["list_tPa5".$part]=$list_t;
			$recodes=$list_t->toArray();
			foreach($recodes as $rec)
			{
				$col_val=$rec[$col_name];
				
			//	$col_ori=$exp[1];
				$col_fun_val= $fun($col_val);
				$v=$this->whereExprs->get("value");
				$v=strtoupper($v);
				$col_fun_val= strtoupper($col_fun_val);
				$con_fun_val_obj=new String($col_fun_val);
				if( $con_fun_val_obj->contains(	$v))
					$li->add($rec);
			}
		
				
				
		}
		
		return $li;
		
		
	 
	}
	
	private Function getCateCnnameDir($cate) {
		$s = pathx.classPathParent_jensyegeor() + "/cate.txt";
	//	cate_file = s;
		$m = YamlAtiX.getMap(s);
		return (String) m.get(cate);
	}
	public Function list_by_partition($partition) {
	 
		$cur_partition_dirname = $this->table."/" . $partition;
		 $GLOBALS["cur_partition_dirname"+$partition]=$cur_partition_dirname;
	//	 echo $cur_partition_dirname;//d:/z/閻栬鲸鍎忕猾锟�
	  
		$subDirs = new ArrayList ();
	
		try {
			$dirx=new dirx($cur_partition_dirname);
			$subDirs = $dirx->subDirs();
		} catch (Exception $e) {
			// TODO Auto-generated catch block
		//	e.printStackTrace();
		}
			
	//	if($partition=="閻栬鲸鍎忕猾锟�")
		   $GLOBALS["subDirs_love"+$partition]=$subDirs;
		 //  print_r($subDirs);
		
		
		$movs = new ArrayList ();
		$mov_names = $subDirs->toArray();
		foreach ($mov_names as  $mov_name   ) {
			try {
				$resDir = $cur_partition_dirname . "/" . $mov_name;
				$GLOBALS["resdir"]=$resDir;
		//					 	print_r($GLOBALS);// [resdir] => d:/z/閻栬鲸鍎忕猾锟�/100濞嗏�虫懃濞夛拷
			
			//$colsx= ;
			$mv =   $this->colsGener->exe($resDir);
			
				$GLOBALS["mvPa4"]=$mv;
				
			
			$mv=$mv->toPhpArr();
				 
				
				$movs->add($mv);
			} catch (Exception $e) {
				e.printStackTrace();
			}

		}
		$GLOBALS["movsPaa4"]=$movs;
		//print_r($GLOBALS);die();
		return $movs;
	}

//ret  List<String>
	private  Function listPatition() {
		$dix=new dirx(  $this->table );
		$subDirs =$dix ->subDirs();
		$GLOBALS["tablePa"]= $this->table;
		$GLOBALS["subdirs"]=$subDirs;
 		return $subDirs;
	}

	
	 
}





?>